<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>给一段文章中的全部指定词语进行过滤</title>
</head>
<body>
    
</body>
<script>
    var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd';
    //假设过滤"SM"
    
    
    let newStr = str.replace("SM", "**");
    while (newStr.indexOf("SM") !== -1) {
        newStr = newStr.replace('SM', '**');
    }
    console.log(newStr);
</script>
</html>